package net.sudot.chess.business.wechat.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import net.sudot.chess.config.SystemProperties;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 微信菜单点击事件处理(转接客服)
 *
 * @author tangjialin on 2017-05-04 0004.
 */
@Component
public class CustomerServiceHandler extends AbstractHandler {

    @Resource
    private SystemProperties systemProperties;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        String customerServerMediaId = systemProperties.getWechat().getCustomerServerMediaId();
        return WxMpXmlOutMessage.IMAGE().mediaId(customerServerMediaId)
                .fromUser(wxMessage.getToUser())
                .toUser(wxMessage.getFromUser()).build();
    }

}
